package org.feng.wrapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.feng.entity.pojo.Menu;
import org.feng.entity.vo.MenuTreeVO;
import org.feng.entity.vo.MenuVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author feng
 */
public class MenuWrapper {

    public static MenuWrapper build() {
        return new MenuWrapper();
    }

    public MenuVO entityVO(Menu menu) {
        return BeanUtil.toBean(menu, MenuVO.class);
    }

    public IPage<MenuVO> entityPageVO(IPage<Menu> page) {
        List<MenuVO> menuVOList = page.getRecords().stream().map(item -> {
            return BeanUtil.toBean(item, MenuVO.class);
        }).collect(Collectors.toList());
        Page<MenuVO> menuPage = new Page<>();
        BeanUtil.copyProperties(page, menuPage);
        menuPage.setRecords(menuVOList);
        return menuPage;
    }

    public List<MenuVO> entityListVO(List<Menu> menu) {
        return menu.stream().map(item -> {
            return BeanUtil.toBean(item, MenuVO.class);
        }).collect(Collectors.toList());
    }


    public List<MenuTreeVO> entityTreeListVO(List<Menu> menu) {
        return menu.stream().map(item -> {
            return BeanUtil.toBean(item, MenuTreeVO.class);
        }).collect(Collectors.toList());
    }
}
